package com.iona.servlets;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.iona.domain.BaseEntity;
import com.iona.domain.Knowleges;
import com.iona.domain.MethodsOfFormation;
import com.iona.json.JSONException;
import com.iona.utils.CreatorUtil;
import com.iona.utils.Storage;

/**
 * Servlet implementation class AddMethodsOfFormationServlet
 */
@WebServlet("/addmethodsofformation")
public class AddMethodsOfFormationServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;

	@Override
	public void init() throws ServletException {
		super.init();
		setTransactional(true);
	}
	public void doExecute(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException,
			JSONException {
		String name = request.getParameter("name");
		MethodsOfFormation mof = CreatorUtil.createMethodsOfFormation(name);
		List<BaseEntity> toCreate = new ArrayList<BaseEntity>();
		toCreate.add(mof);
		new Storage().storeAll(toCreate, null, null);
		// TODO: add ajax response
		// goToList(request, response);
	}
	}
